uni.addInterceptor('request', {
	invoke(args) {
		
		const config = "http://localhost:8081/";
		args.url = config + args.url
		
		args.header = {
			...args.header,
			Authorization:`Bearer${uni.getStorage("token")}`
		}
		
		console.log(args.url)
		let token = uni.getStorageSync("token");
		if (args.url != config + "productSpu/list" && args.url != config + "seckill/list" && args.url != config + "navigation/list") {
			if (args.url != "user/login") {
				if (args.url.indexOf("?") == -1) {
					console.log("进入")
					args.url += "?token=" + token
				} else {
					args.url += "&token=" + token
				}
			}
		}

	},
	returnValue(args) {
		return args.data;
	},
	success(args) {
		if(args.data.code == "403"){
			uni.showToast({
				title:"权限不足"
			})
		} else if(args.data.code == "402"){
			uni.showToast({
				title:"账号或密码错误"
			})
		} else if(args.data.code == "401"){
			uni.reLaunch({
				url:"/pages/component/login"
			})
		}
	},
	fail(err) {
		console.log(err)
	},
	complete(res) {
		console.log(res)
	}
})

uni.addInterceptor('navigateTo', {
	invoke(args) {
		console.log('url', args.url);
		const token = uni.getStorageSync("token");
		console.log("token",token);
		if (token === "" && args.url != "/pages/component/login") {
			
			console.log("进入该方法")

			// uni.setStorageSync('argsUrl', agrs.url);

			args.url = "/pages/component/login"
			// console.log(args.url)
			
		}
	},
	success(args) {
		console.log('成功')
	},
	fail(err) {
		console.log(err)
	},
	complete(res) {
		console.log(res)
	}
})